
#include "xlogy_tiling.h"
#include "register/op_def_registry.h"
#include "tiling_common.h"

namespace optiling {
static ge::graphStatus TilingFunc(gert::TilingContext* context)
{

  XlogyTilingData tiling;
  auto size = set_size_by_input(tiling, context, 0);
  COMMON_TILING_GET_PLATFORM;
  COMMON_TILING_GET_UB_SIZE;
  auto dtype = context->GetInputDesc(0)->GetDataType();
  auto dtypeSize = GetSizeByDataType(dtype);

  context->SetBlockDim(1);

  // 分割UB
  // x1 * 2, x2 * 2, y * 2; ;
  // 需要一个tempB
  // 
  auto count = 6 + 1;
//   if (dtype == ge::DataType::DT_FLOAT16) {
    // count = 4 + 4 + 4;
//   }
  auto split_ub = ub_size / count / 256 * 256 / dtypeSize;
  tiling.set_size(size);
  tiling.set_tileLength(split_ub);
  tiling.set_finalLength(size % split_ub);
  std::cout << "size = " << tiling.get_size() << std::endl;
  std::cout << "tileLength = " << tiling.get_tileLength() << std::endl;
  std::cout << "finalLength = " << tiling.get_finalLength() << std::endl;
  tiling_zero_workspace(context);
  tiling_save_to_buffer(tiling, context);
  return ge::GRAPH_SUCCESS;
}
}


namespace ge {
static ge::graphStatus InferShape(gert::InferShapeContext* context)
{
    const gert::Shape* x1_shape = context->GetInputShape(0);
    gert::Shape* y_shape = context->GetOutputShape(0);
    *y_shape = *x1_shape;
    return GRAPH_SUCCESS;
}
}


namespace ops {
class Xlogy : public OpDef {
public:
    explicit Xlogy(const char* name) : OpDef(name)
    {
        this->Input("x1")
            .ParamType(REQUIRED)
            .DataType({ge::DT_FLOAT16, ge::DT_FLOAT})
            .Format({ge::FORMAT_ND, ge::FORMAT_ND})
            .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND});
        this->Input("x2")
            .ParamType(REQUIRED)
            .DataType({ge::DT_FLOAT16, ge::DT_FLOAT})
            .Format({ge::FORMAT_ND, ge::FORMAT_ND})
            .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND});
        this->Output("y")
            .ParamType(REQUIRED)
            .DataType({ge::DT_FLOAT16, ge::DT_FLOAT})
            .Format({ge::FORMAT_ND, ge::FORMAT_ND})
            .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND});

        this->SetInferShape(ge::InferShape);

        this->AICore()
            .SetTiling(optiling::TilingFunc);
        this->AICore().AddConfig("ascend310b");

    }
};

OP_ADD(Xlogy);
}
